from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import logging

secret_id = 'AKIDgBPRCfrmQovlKcVEhz4uUpthFYbNt99t'  # 替换为用户的 secretId
secret_key = 'Xoqc8NN7aomVx94kALFtHPIvHNDsHQJv'  # 替换为用户的 secretKey
region = 'ap-chengdu'  # 替换为用户的 Region

config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)

client = CosS3Client(config)

# 特别注意
# cos的桶名格式是：bucket name-appid组成的。 appid 是我腾讯云的appid
response = client.create_bucket(
    Bucket='test-1309510181',
    ACL="public-read"  # private  /  public-read / public-read-write
)

# 上传文件
# response = client.upload_file(
#     Bucket='tangzhiming-1309510181',
#     LocalFilePath='code.png',  # 本地文件的路径
#     Key='p1.jpg',  # 上传到桶之后的文件名
# )
# print(response['ETag'])
